<?php
session_start();
error_reporting(0);
if($_SESSION['username']!="")
{
?>
<!DOCTYPE html>
<html lang="en">
 <head>
     <? include "./include/head.php"; ?>
	  <? include "./include/js.php"; ?>
  </head>
  <body>
  <? include "./include/body.php"; ?>
        <div class="span9">
        <div class="hero-unit">  
        <?php
        include "./config/connection.php";
        include "./config/rupiah.php";
        error_reporting(0);
		$id_pemesanan = $_GET['id_pemesanan'];
        $perintah="SELECT * FROM pemesanan where id_pemesanan='".$id_pemesanan."'";
	$hasil=mysql_query($perintah);
	$baris=mysql_fetch_array($hasil);
	error_reporting(0);
	$input = $_GET["input"];
					if($input == "invalid")
					{
						echo"<b>Sorry form input not completed, please correct it</b>" ;
					}
					
	//DETAIL
        
	?>
          <form class="form-horizontal" action="order_update.php" method="post" enctype="multipart/form-data">
            <fieldset>
             <div class="control-group">
                  <label class="control-label" for="input01" >Id Pemesanan</label>	
					<div class="controls">
                        <input type="text" class="input-xlarge" name="id_pemesanan" size="30" readonly="yes" value="<?php echo "$baris[id_pemesanan]";?>">
                        <p class="help-block"></p>
                    </div>
					
				<label class="control-label" for="input011">Tanggal Pemesanan</label>
                    <div class="controls">
                        <input type="text" name="tanggal" readonly="yes" class="input-xlarge" value="<?php echo "$baris[tanggal]";?>">
                        <p class="help-block"></p>
                    </div>
               <div class="control-group">
                  <label class="control-label" for="input01">Nama Pemesan</label>
                    <div class="controls">
                        <input type="text" class="input-xlarge" readonly="yes" name="nama_pemesan" size="30"  value="<?php echo "$baris[nama_pemesan]";?>">
                        <p class="help-block"></p>
                    </div>
                  <label class="control-label" for="input011">Alamat</label>
                    <div class="controls">
                        <textarea name="alamat" readonly="yes" class="input-xlarge" rows="9"><?php echo "$baris[alamat]";?></textarea>
                        <p class="help-block"></p>
                    </div>
					<label class="control-label" >Provinsi </label>
                    <div class="controls">
                        <input type="text" readonly="yes" class="input-xlarge" name="propinsi size="30" value="<?php echo "$baris[propinsi]";?>">
                         <p class="help-block"></p>
                    </div>
                  <label class="control-label" >Kota </label>
                    <div class="controls">
                        <input type="text" readonly="yes" class="input-xlarge" name="kota" size="30" value="<?php echo "$baris[kota]";?>">
                         <p class="help-block"></p>
                    </div>
                  <label class="control-label" >Telepon </label>
                    <div class="controls">
                        <input type="text" readonly="yes" class="input-xlarge" name="telepon" size="30" value="<?php echo "$baris[telepon]";?>">
                         <p class="help-block"></p>
                    </div>
                  <label class="control-label" >Email </label>
                    <div class="controls">
                        <input type="text" readonly="yes" class="input-xlarge" name="email" size="30" value="<?php echo "$baris[email]";?>">
						<p class="help-block"></p>
                    
                    </div>
                  <label class="control-label" >Status</label>
                    <div class="controls">
                        <input type="text" class="input-xlarge" name="status" size="30" value="<?php echo "$baris[status]";?>">
						
                       &nbsp;&nbsp;&nbsp;*Lunas / Baru
                    </div>
					
					    </div>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button class="btn btn-danger" type="submit">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Update Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </button>
                &nbsp;&nbsp;&nbsp;
                <button class="btn btn-danger" type="reset" value="Reset">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </button>
                </div> 
                
                
            </fieldset>
        </form>
       
	    <table class="table table-striped">							
						
						<thead>								
                                    <td><b>Nama Produk<b></td>
                                    <td><b>Berat <b></td>
                                    <td><b>Jumlah<b></td>
                                    <td><b>Harga Satuan</b></td>
									<td><b>SUB TOTAL</b></td>
                        </thead>    
		
            <?php
            $sql2=mysql_query("SELECT * FROM pemesanan_detail, produk 
                     WHERE pemesanan_detail.id_produk=produk.id_produk 
                     AND pemesanan_detail.id_pemesanan='$_GET[id_pemesanan]'");
            
            while($s=mysql_fetch_array($sql2)){
            // rumus untuk menghitung subtotal dan total		
            $hargadisc   = number_format(($s[harga]),0,",","."); 
            $subtotal    = ($s[harga]) * $s[jumlah];

            $total       = $total + $subtotal;
            $subtotal_rp = format_rupiah($subtotal);    
            $total_rp    = format_rupiah($total);    
            $harga       = format_rupiah($s[harga]);

            $subtotalberat = ($s[berat]/1000) * $s[jumlah]; // total berat per item produk 
            $totalberat  = $totalberat + $subtotalberat; // grand total berat all produk yang dibeli
            
            //ongkos kirim
            $ongkos=mysql_fetch_array(mysql_query("SELECT * FROM ekspedisi,pemesanan WHERE pemesanan.id_ekspedisi=ekspedisi.id_ekspedisi AND id_pemesanan='$_GET[id_pemesanan]'"));
            $ongkoskirim1=$ongkos[harga];
            $ongkoskirim=$ongkoskirim1 * $totalberat;

            $grandtotal    = $total + $ongkoskirim; 

            $ongkoskirim_rp = format_rupiah($ongkoskirim);
            $ongkoskirim1_rp = format_rupiah($ongkoskirim1); 
            $grandtotal_rp  = format_rupiah($grandtotal); 
			
            ?>
			
			
							<tr>
                                <td><?php echo $s[nama_produk];?></td>
                                <td><?php echo $s[berat]/1000;?></td>
								<td><?php echo $s[jumlah];?></td>
                                <td>Rp. <?php echo $harga;?></td>
                                <td>Rp. <?php echo $subtotal_rp;?></td>
                            </tr>        
<?php }; ?>
                                 <tr>
                                        <td></td>
                                        <td></td>
                                        <td>Total</td>
										<td></td>
                                        <td>Rp. <?php echo $total_rp;?></td>
                                
                                </tr>
						
								<tr>
                                        <td></td>
                                        <td></td>
                                        <td>Ongkos Kirim</td>
								<td></td>
                                         <td>Rp. <?php echo $ongkoskirim1_rp;?> /kg</td>
                                
                                        </tr>
                                <tr>
                                        <td></td>
                                        <td></td>
                                        <td>Berat Total</td>
								<td></td>
                                        <td><?php echo $totalberat;?> kg</td>
                                
                                </tr>
                                <tr>
                                        <td></td>
                                        <td></td>
                                        <td>Total Ongkos Kirim</td>
								<td></td>
                                        <td>Rp. <?php echo $ongkoskirim_rp;?></td>
                                
                                </tr>
                                <tr>
                                        <td></td>
                                        <td></td>
                                        <td>Jumalh Total</td>
								<td></td>
                                        <td>Rp. <?php echo $grandtotal_rp;?></td>
                                
                                 </tr>
							</table>
            
          </div>
          </div><!--/row-->

         
            </div><!--/span-->
          </div><!--/row-->
        </div><!--/span-->
      </div><!--/row-->

      <hr>

    <? include "./include/menubawah.php"; ?>
   
  </body>
</html>
<?php
    }
else {
    include 'warning.php';
}
?>